#include "check_run.h"

int check_run(char *progname)
{   
    char starter_pid_file_default[512];

    snprintf(starter_pid_file_default, sizeof(starter_pid_file_default), "/var/run/%s.pid", progname); 
    FILE *fd = fopen(starter_pid_file_default, "w");
 
    if (fd)
    {
        fprintf(fd, "%u\n", getpid());
        fclose(fd);
    }
    if (check_pid(starter_pid_file_default))
    {
        printf("Program is already running (%s exists)\n", starter_pid_file_default);
        
    }
    else
        printf("Program is NOT running (%s NOT exists)\n", starter_pid_file_default);
    
    unlink(starter_pid_file_default);

    return 0;  
}
